import React, { HTMLAttributes, useRef } from 'react'; import './index.scss'; export type Tip = { id: number; message: React.ReactNode; }; export interface DropdownProps extends HTMLAttributes { children?: React.ReactNode; tips?: Tip[]; } const Dropdown: React.FC = (props) => { const { children, tips, ...rest } = props; const tipWrapRef = useRef(null); const tipRef = useRef(null); const open = () => { tipWrapRef.current!.style.height = `${tipRef.current!.getBoundingClientRect().height}px`; }; const close = () => { tipWrapRef.current!.style.height = '0px'; }; return (
{children}
{tips?.map((item) => { return (
{item.message}
); })}
); }; Dropdown.defaultProps = { children: '', tips: [] }; export default Dropdown;